package com.alibaba.algo.domain.dict;

import com.alibaba.algo.core.base.BaseDomain;
import com.alibaba.algo.core.base.CoreTools;
import com.alibaba.algo.core.base.Pager;
import com.alibaba.algo.core.base.PagerEntity;
import com.alibaba.algo.dao.dict.SysDictMapper;
import com.alibaba.algo.entity.dict.SysDict;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * 数据字典domain
 */
@Component
public class SysDictDomain extends BaseDomain<SysDict> {

    @Resource
    private SysDictMapper sysDictMapper;

    public PagerEntity selectPage(SysDict sysDict, Integer pageIndex, Integer pageSize, LinkedHashMap<String, Object> sortMap) {
        Integer count = sysDictMapper.countByPara(sysDict);

        Pager pager = Pager.newInstance(Long.valueOf(count), pageIndex, pageSize);
        List<SysDict> result = sysDictMapper.pageByPara(sysDict, pager.getStart(), pager.getEnd(), CoreTools.getSortStr(sortMap));
        return new PagerEntity(count, pager.getTotalPages(), pager.getPageSize(), pager.getPageIndex(), result);
    }
}
